Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement node Timer api when running in node environment. #4622

Merged
merged 4 commits into from
Oct 8, 2017

Conversation

skrivle
Copy link
Contributor

@skrivle skrivle commented Oct 7, 2017

Fixes #4559. Not entirely sure if this is the right approach. Let me know if there's a better way!

Some thoughts:

  • I'm a little unsure about the name TimerRef (I consider it to be a reference to the timer that is used to clear it)
  • we might want to assert if ref/unref are really functions but I noticed this isn't always done in other places in the codebase
  • maybe we also need to verify the return values of ref/unref?
  • I had to shuffle the FakeTimer constructor args a little bit since some are optional. I considered making timerConfig an optional arg with a default implementation but given that FakeTimer is generic about TimerRef, I couldn't get Flow to typecheck it properly.

Any feedback is more then welcome.

Thanks!

@codecov-io
Copy link

codecov-io commented Oct 7, 2017

Codecov Report

Merging #4622 into master will increase coverage by 0.19%.
The diff coverage is 80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4622      +/-   ##
==========================================
+ Coverage   56.17%   56.37%   +0.19%     
==========================================
  Files         194      194              
  Lines        6544     6551       +7     
  Branches        3        3              
==========================================
+ Hits         3676     3693      +17     
+ Misses       2867     2857      -10     
  Partials        1        1
Impacted Files Coverage Δ
packages/jest-util/src/fake_timers.js 91.04% <100%> (+0.09%) ⬆️
packages/jest-environment-node/src/index.js 62.5% <66.66%> (-0.66%) ⬇️
packages/jest-environment-jsdom/src/index.js 44.44% <75%> (+44.44%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f264780...22c673a. Read the comment docs.

@cpojer cpojer requested a review from SimenB October 7, 2017 12:04
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Only thing I'd change is to not overload the FakteTimers constructor and instead use an object, but no biggie

refToId: (ref: number) => ref,
};

this.fakeTimers = new FakeTimers(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make the constructor take an object instead of multiple arguments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Updated.

const timer2 = env1.global.setInterval(() => {}, 0);

[timer1, timer2].forEach(timer => {
expect(timer.id).not.toBe(undefined);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not.toBeUndefined()

@SimenB
Copy link
Member

SimenB commented Oct 8, 2017

CI has finished succesfully, not sure why it's still reported as in progress here.

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fake Timer implementation does not have unref method in Node environment
5 participants